package com.syl.controller;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter; 

public class Test2 extends Thread{
	static String path = "C://Users//Admin//Desktop//链接超时url.txt";
	
	public static void main(String[] args) {
		//write();
		//read();
	}

	private static void write(String str){
		OutputStreamWriter sw = null;
		try {
			File f = new File(path);
			if(!f.exists())new OutputStreamWriter(new FileOutputStream(path),"UTF-8").close();
			sw = new OutputStreamWriter(new FileOutputStream(path),"UTF-8");
			
			sw.write(new String(str.getBytes(),"UTF-8"));
			sw.close();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
	private static void read(){
		InputStreamReader ir = null;
		BufferedReader br = null;
		try {  
			File f = new File(path);
			if(!f.exists())new OutputStreamWriter(new FileOutputStream(path),"UTF-8").close();
			ir = new InputStreamReader(new FileInputStream(path));//,"UTF-8"
			br=new BufferedReader(ir); 
			StringBuffer sb = new StringBuffer();
			String s;
			while ((s = br.readLine() )!=null) { 
				sb.append(s);
			}
			System.out.println(sb.toString());

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				br.close();
				ir.close();
			} catch (Exception e2) {
				// TODO: handle exception
			}
		}
	}

}
